// clang-format off
#include <windows.h>
#include <winioctl.h>
#include <ntddser.h>
#include <stdio.h>
#include <stdlib.h>
// clang-format on

#define FILE_DEVICE_CUSTOM 0x8888
#define IOCTL_CUSTOM_HELLO CTL_CODE(FILE_DEVICE_CUSTOM, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)

class VSPDevice
{
  public:
    VSPDevice() : m_hDevice(INVALID_HANDLE_VALUE), m_dwErrCode(0)
    {
        m_hDevice = CreateFile(m_devicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
    }

    virtual ~VSPDevice()
    {
        if (INVALID_HANDLE_VALUE != m_hDevice)
        {
            CloseHandle(m_hDevice);
        }
    }

    DWORD Commond(DWORD dwIoControlCode, void* pParam, unsigned int uSize)
    {
        DWORD dwReturned = 0;
        if (INVALID_HANDLE_VALUE != m_hDevice)
        {
            return (DeviceIoControl(m_hDevice, dwIoControlCode, pParam, uSize, NULL, 0, &dwReturned, NULL) ? 0 : 1);
        }
        return 2;
    }

  private:
    HANDLE  m_hDevice;
    DWORD   m_dwErrCode;
    LPCWSTR m_devicePath = L"\\\\.\\VSP";
};

int main()
{
    int* pNum = new int(0x123);
    printf("%d  %d-->%p\n", __LINE__, *pNum, pNum);
	system("pause");
    printf("%d  %d-->%p\n", __LINE__, *pNum, pNum);
    system("pause");
    return 0;
    typedef struct _HelloInfor
    {
        ULONG uLineNumber;
        CHAR  szHello[512];
    } HelloInfor, *PHelloInfor;

    HelloInfor helloInfor;
    memset(&helloInfor, 0, sizeof(HelloInfor));
    helloInfor.uLineNumber = __LINE__;
    strcpy_s(helloInfor.szHello, "Hello,Driver!");

    VSPDevice VSPDev;
    VSPDev.Commond(IOCTL_CUSTOM_HELLO, &helloInfor, sizeof(HelloInfor));

    return 0;
}
